package com.kewu.common.global;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public <T> ResponseData<T> customExceptionHandler(CustomException e, HttpServletRequest request) {
        ResponseData resultVO = e.resp();
        log.warn(String.format("接口:[%s], 响应异常结果:=>%s", request.getRequestURI(), resultVO), e);
        return resultVO;
    }

//    @Order(1000000)
//    @ExceptionHandler(Exception.class)
//    @ResponseBody
//    public ResponseData<Void> exceptionHandler(Exception e, HttpServletRequest request) {
//        log.error("系统异常");
//        return ResponseData.error("14562", "系统异常");
//    }
}
